package com.example.music_project.tools;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       // 判断是否已经登录
        HttpSession session = request.getSession(false);
        if(session == null || session.getAttribute(Constant.USER_SESSION)== null) {
            System.out.println("未登录!!!");
            response.setStatus(401);
            return false;
        }
        return true;

                /*
        1. 从header中获取token
        2.校验token
         */
//        String userToken = request.getHeader("user_token_header");
//        System.out.println("userToken:" + userToken);
//        boolean checkToken = JWTUtils.verifyToken(userToken);
//        if(checkToken) {
//            //校验成功
//            return true;
//        }
//        response.setStatus(401);
//        return false;
    }
}
